package edu.pku.sei.act.ctrl.command;

import org.eclipse.gef.commands.Command;

import edu.pku.sei.act.model.common.ArchiModel;
import edu.pku.sei.act.model.mote.Radio;

public class DeleteRadioCommand extends Command {
	
	private ArchiModel model;
	private Radio radio;

	public DeleteRadioCommand(Radio radio) {
		super("Delete Radio");
		this.radio = radio;
		if (radio.getContainer() instanceof ArchiModel) {
			model = (ArchiModel) radio.getContainer();
		}
	}

	public boolean canExecute() {
		return radio != null &&  model != null;
	}

	public void execute() {
		if (model != null) {
			model.getRootElements().remove(radio);
		}
		radio.setContainer(null);
	}

	public void undo() {
		if (model != null) {
			radio.setContainer(model);
			model.getRootElements().add(radio);
		}
	}

}
